<template>
	<view class="container bg-white">
		<view class="panel-header padding-top solid-bottom">
			<view class="g-goBack" @click="$utils.toBack()">
				<view class="cuIcon-back"></view>
			</view>
			<view class="text-cut">【充电插座订单】{{tradeNo}}</view>
		</view>
		<view class="headBar">
			<view class="tabBar">
				<view :class="'item '+(tabBarIndex==1?'cur':'')" @click="execute(1)">操作记录</view>
				<view :class="'item '+(tabBarIndex==2?'cur':'')" @click="execute(2)">扣费记录</view>
			</view>
		</view>
		<block v-if="tabBarIndex == 1">
			<view class="cu-timeline" v-for="(item,index) in listData" :key="index">
			  <view class="cu-time">{{item.dateStr}}</view>
			  <view class="cu-item cuIcon-noticefill" v-for="(child,childIndex) in item.items" :key="childIndex">
			    <view class="content shadow-blur" :class="child.state == 4?'bg-red':'bg-grey'">
			      <text>【{{child.timeStr}}】</text>{{child.content}}
				  <view v-if="child.errorsMsg && child.errorsMsg.length > 0">{{child.errorMsg}}</view>
			    </view>
			  </view>
			</view>
			<view class="foot" v-if="listData && listData.length > 0"><text class="ftxt">我也是有底线的</text></view>
			<view class="foot" v-else><text class="ftxt">暂无数据</text></view>
		</block>
		<block v-if="tabBarIndex == 2">
			<view class="cu-timeline" v-for="(item,index) in chargeListData" :key="index">
				<view class="cu-item" :class="item.state==1?'text-orange':''">
				  <view class="content shadow-blur">
					<view class="title flex justify-between align-center">
						<view>{{item.createDate}}</view>
						<view class="cu-capsule radius">
						  <view class="cu-tag" :class="item.state==1?'bg-orange':'bg-grey'">
							<text :class="'cuIcon-'+(item.state==1?'check':'close')"></text>
						  </view>
						  <view class="cu-tag" :class="item.state==1?'line-orange':'line-grey'">{{item.stateName}}</view>
						</view>
					</view>
					<view>操作内容：{{item.content}}</view>
					<view v-if="item.errorsMsg">错误提示：{{item.errorsMsg}}</view>
				  </view>
				</view>
			</view>
			<view class="foot" v-if="chargeListData && chargeListData.length > 0"><text class="ftxt">我也是有底线的</text></view>
			<view class="foot" v-else><text class="ftxt">暂无数据</text></view>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tradeNo:null,
				createDate:null,
				tabBarIndex:1,
				
				listData:[],
				chargeListData:[]
			}
		},
		onLoad(option) {
			this.tradeNo = option.tradeNo;
			this.createDate = option.createDate;
			this.execute(1);
		},
		methods: {
			execute(index){
				this.tabBarIndex = index;
				if(index == 1){
					this.getInfo1();
				}else{
					this.getInfo2();
				}
			},
			getInfo1(){
				const _self = this;
				const api = this.$request;
				api.post(api.url.orderOperateList,{
					tradeNo:this.tradeNo,
					createDate:this.createDate,
					businessType:'CDCZ'
				},res=>{
					if(res.code == 200){
						_self.listData = res.body.items;
					}else{
						_self.listData = [];
					}
				})
			},
			getInfo2(){
				const _self = this;
				const api = this.$request;
				api.post(api.url.cdczOrderRecord,{
					tradeNo:this.tradeNo,
					createDate:this.createDate
				},res=>{
					if(res.code==200){
						this.chargeListData = res.body.items;
					}else{
						this.chargeListData = [];
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.container{height:100vh;}
	.cu-timeline .cu-time{width:200rpx;}
	.headBar{
		background-color: white;
		padding: 20rpx 0 0;
		z-index: 200;
		width: 100%;
		box-shadow: 0 0 10rpx #e0e0e0;
		.tabBar{
			margin-top: 20rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			.item{
				padding:10rpx 10rpx 12rpx;
				border-bottom: 4rpx solid transparent;
				color: #999999;
				&.cur{
					font-weight: 600;
					color: #e29751;
					border-bottom: 4rpx solid #e29751;
				}
			}
		}
	}
	.title{
		padding-bottom: 10rpx;
		border-bottom: 1rpx solid white;
		margin-bottom: 10rpx;
	}
</style>
